package com.hyh.admin.controller;

import com.hyh.ad.common.core.domain.AjaxResult;
import com.hyh.admin.service.IMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/im")
@Api(tags = "IM-消息列表")
public class MessageController {
     @Autowired
     private IMessageService messageService;

     /*
      * 得到消息列表
      */
     @GetMapping("/message/list/{id}")
     @ApiOperation("获取消息列表")
     public AjaxResult getMessage(@PathVariable("id") Long id) {
         return AjaxResult.success("操作成功",messageService.listMessage(id));
     }

     /*
      * 修改消息状态
      */
     @GetMapping("/message/update/{ids}")
     @ApiOperation("修改消息状态")
     public AjaxResult updateMessageStatus(@PathVariable("ids") Long[] ids) {
          messageService.updateMessageStatus(ids);
          return AjaxResult.success("操作成功");
     }


     /*
      * 获取用户之间未读的消息数量
      */
        @GetMapping("/message/unread/{id}")
        @ApiOperation("获取用户之间未读的消息数量")
        public AjaxResult getUnreadMessage(@PathVariable("id") Long id) {
            return AjaxResult.success("操作成功",messageService.getUnreadMessage(id));
        }

        /**
         * 将消息设置为已读
         */
        @GetMapping("/read/{id}")
        @ApiOperation("将消息设置为已读")
        public AjaxResult readMessage(@PathVariable("id") Long id) {
            return AjaxResult.success("操作成功", messageService.readMessage(id));
        }

        /**
         * 获取最近的一条消息
         */
        @GetMapping("/message/latest/{id}")
        @ApiOperation("获取最近的一条消息")
        public AjaxResult getLatestMessage(@PathVariable("id") Long id) {
            return AjaxResult.success("操作成功", messageService.getLatestMessage(id));
        }
}
